/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package webService;

import Outils.LiaisonRMI;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import server.*;

/**
 * REST Web Service
 *
 * @author smng2095
 */
@Path("ws")
public class WS_Monitor {

    @Context
    private UriInfo context;

    /**
     * Creates a new instance of WS_Monitor
     */
    public WS_Monitor() {
    }

    /**
     * Retrieves representation of an instance of webService.WS_Monitor
     * @return an instance of java.lang.String
     */
    @GET
    @Path("/monitor/{serveur}")
    @Produces("text/xml")
    public ServerHealth getMonitorXml(@PathParam(value = "serveur") String serveur) {
	 ServerHealth r = null ;
	try {
	   
	    r = (new LiaisonRMI(serveur, "MonitoringServer")).getMonitor();
	           System.out.println(r.getMemory());
	} catch (RemoteException ex) {
	    Logger.getLogger(WS_Monitor.class.getName()).log(Level.SEVERE, null, ex);
	} catch (NotBoundException ex) {
	    Logger.getLogger(WS_Monitor.class.getName()).log(Level.SEVERE, null, ex);
	} catch (MalformedURLException ex) {
	    Logger.getLogger(WS_Monitor.class.getName()).log(Level.SEVERE, null, ex);
	}
    return r;
    
    }

    /**
     * PUT method for updating or creating an instance of WS_Monitor
     * @param content representation for the resource
     * @return an HTTP response with content of the updated or created resource.
     */
    @PUT
    @Consumes("application/xml")
    public void putXml(String content) {
    }
}
